//
//  SRSleepingView.m
//  SportRing
//
//  Created by icelee on 14-10-27.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRSleepingView.h"

#define TEXT_SIZE 22

@implementation SRSleepingViewModel

- (id)initWithDeepTime:(float )deepTime simpleTime:(float)simpleTime activeTime:(float)activeTime sleepingQuality:(float)sleepingQuality sleepingTip:(NSString *)sleepingTip;
{
    self = [super init];
    if (self) {
        
        self.deepSleepingTime = deepTime;
        self.simpleSleepingTime = simpleTime;
        self.activeTime = activeTime;
        self.sleepingQuality = sleepingQuality;
        self.sleepingTip = sleepingTip;
        
    }
    return self;
}

@end


@interface SRSleepingView ()

@property (nonatomic, weak)IBOutlet UILabel *totalSleepingTimeLabel;
@property (nonatomic, weak)IBOutlet UILabel *deepSleepingTimeLabel;
@property (nonatomic, weak)IBOutlet UILabel *simpleSleepingTimeLabel;
@property (nonatomic, weak)IBOutlet UILabel *activeTimeLabel;
@property (nonatomic, weak)IBOutlet UITextField *sleepingTipTextField;
@property (nonatomic, weak)IBOutlet UIView *evaluateViewContainerView;

@end

@implementation SRSleepingView

- (void)awakeFromNib
{
    
    [super awakeFromNib];
    
    [self setSRSleepingDataViewModel:nil];
    
    self.sleepingTipTextField.hidden = YES;
}

- (void)setSRSleepingDataViewModel:(SRSleepingViewModel *)model
{

    NSAttributedString *totalSleepingTime = [SRHelper attString:[NSString stringWithFormat:@"%ldh%ldm",(long)[SRHelper getHoursFromTime:model.deepSleepingTime +model.simpleSleepingTime+ model.activeTime],(long)[SRHelper getMinutesFromTime:model.deepSleepingTime +model.simpleSleepingTime+ model.activeTime]]
                                       fromString:[[NSMutableArray alloc] initWithObjects:@"",@"h", nil]
                                         toString:[[NSMutableArray alloc] initWithObjects:@"h",@"m", nil]
                                         fontSize:[[NSMutableArray alloc] initWithObjects:[UIFont systemFontOfSize:45],[UIFont systemFontOfSize:35], nil]
                                            color:[[NSMutableArray alloc] initWithObjects:self.totalSleepingTimeLabel.textColor,self.totalSleepingTimeLabel.textColor, nil]];
    self.totalSleepingTimeLabel.attributedText = totalSleepingTime;
    
    
    NSAttributedString *deepSleepingTime = [SRHelper attString:[NSString stringWithFormat:@"%ldh%ldm",(long)[SRHelper getHoursFromTime:model.deepSleepingTime],(long)[SRHelper getMinutesFromTime:model.deepSleepingTime]]
                                       fromString:[[NSMutableArray alloc] initWithObjects:@"",@"h", nil]
                                         toString:[[NSMutableArray alloc] initWithObjects:@"h",@"m", nil]
                                         fontSize:[[NSMutableArray alloc] initWithObjects:[UIFont systemFontOfSize:TEXT_SIZE],[UIFont systemFontOfSize:TEXT_SIZE], nil]
                                            color:[[NSMutableArray alloc] initWithObjects:self.totalSleepingTimeLabel.textColor,self.totalSleepingTimeLabel.textColor, nil]];
    self.deepSleepingTimeLabel.attributedText = deepSleepingTime;
    
    NSAttributedString *simpleSleepingTime = [SRHelper attString:[NSString stringWithFormat:@"%ldh%ldm",(long)[SRHelper getHoursFromTime:model.simpleSleepingTime],(long)[SRHelper getMinutesFromTime:model.simpleSleepingTime]]
                                                    fromString:[[NSMutableArray alloc] initWithObjects:@"",@"h", nil]
                                                      toString:[[NSMutableArray alloc] initWithObjects:@"h",@"m", nil]
                                                      fontSize:[[NSMutableArray alloc] initWithObjects:[UIFont systemFontOfSize:TEXT_SIZE],[UIFont systemFontOfSize:TEXT_SIZE], nil]
                                                         color:[[NSMutableArray alloc] initWithObjects:self.totalSleepingTimeLabel.textColor,self.totalSleepingTimeLabel.textColor, nil]];
    self.simpleSleepingTimeLabel.attributedText = simpleSleepingTime;
    
    NSAttributedString *activeTime = [SRHelper attString:[NSString stringWithFormat:@"%ldh%ldm",(long)[SRHelper getHoursFromTime:model.activeTime],(long)[SRHelper getMinutesFromTime:model.activeTime]]
                                                    fromString:[[NSMutableArray alloc] initWithObjects:@"",@"h", nil]
                                                      toString:[[NSMutableArray alloc] initWithObjects:@"h",@"m", nil]
                                                      fontSize:[[NSMutableArray alloc] initWithObjects:[UIFont systemFontOfSize:TEXT_SIZE],[UIFont systemFontOfSize:TEXT_SIZE], nil]
                                                         color:[[NSMutableArray alloc] initWithObjects:self.totalSleepingTimeLabel.textColor,self.totalSleepingTimeLabel.textColor, nil]];
    self.activeTimeLabel.attributedText = activeTime;
    
    
    self.sleepingTipTextField.text = model.sleepingTip;
    
    //sleeping quality.
    SREvaluateView *evaluateView = [[SREvaluateView alloc]  initWithSelectedImage:[UIImage imageNamed:@"moon"] notSelectedImage:[UIImage imageNamed:@"moon_1"] notSelectedCount:5-model.sleepingQuality selectedCount:model.sleepingQuality];
    
    [self.evaluateViewContainerView addSubview:evaluateView];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
